#include "adddatabasedialog.h"

AddDatabaseDialog::AddDatabaseDialog(QWidget *parent) :
    QDialog(parent)
{
    databaseNameLabel=new QLabel(tr("Input database name:"));
    databaseNameEdit=new QLineEdit;
    databaseNameLabel->setBuddy(databaseNameEdit);

    okButton=new QPushButton(tr("&OK"));
    cancelButton=new QPushButton(tr("&Cancel"));

    okButton->setEnabled(false);
    QHBoxLayout* hLayout1=new QHBoxLayout;

    hLayout1->addWidget(databaseNameLabel);
    hLayout1->addWidget(databaseNameEdit);
    QHBoxLayout* hLayout2=new QHBoxLayout;
    hLayout2->addWidget(okButton);
    hLayout2->addWidget(cancelButton);

    QVBoxLayout* vLayout=new QVBoxLayout;
    vLayout->addLayout(hLayout1);
    vLayout->addLayout(hLayout2);
    setLayout(vLayout);
    this->setWindowTitle(tr("Add database dialog"));

    connect(databaseNameEdit,SIGNAL(textChanged(QString)),this,SLOT(enableOkButton(QString)));
    connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
    connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
}

void AddDatabaseDialog::enableOkButton(const QString &databaseName)
{
    okButton->setEnabled(true);
}


const QString AddDatabaseDialog::getDatabaseName()
{
    return databaseNameEdit->text();
}
